package com.xinjian.jianba.config;


import org.redisson.Redisson;
import org.redisson.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

@Component
public class RedissonManager {
	private static final Logger LOGGER = LoggerFactory.getLogger(RedissonManager.class);
    private Config config = new Config();
    private Redisson redisson = null;
   
    @Value("${spring.redis.host}")
	private String host; // Redis服务器地址
	@Value("${spring.redis.port}")
	private int port; // Redis服务器连接端口
	@Value("${spring.redis.password}")
	private String password; // Redis服务器连接密码（默认为空）
    public Redisson getRedisson() {
        return redisson;
    }
    @PostConstruct
    private void init(){
        try {
            config.useSingleServer().setAddress(new StringBuilder().append(host).append(":").append(port).toString()).setPassword(password);

            redisson = (Redisson) Redisson.create(config);

            LOGGER.info("初始化Redisson结束");
        } catch (Exception e) {
        	LOGGER.error("redisson init 失败",e);
        }
    }



}
